local ClientOHOH = _G.ClientOHOH;

local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHOLYBUIBase());
local CallBackManager = ClientOHOH.load.CallBackManager();
local BtnHelper = ClientOHOH.load.BtnHelper();
local LanguageHelper=_G.LanguageHelper 
local BigNumberHelper = ClientOHOH.load.BigNumberHelper();
local ConnectClass=_G.CommonOHOH.load.Connect();

function InitInsts(ui)
    ui.insts = {};

    ui.insts.hpClipping = "ctrl.hp.Clipping"
    ui.insts.hpText = "ctrl.hp.text"

    ui.insts.attack = "ctrl.valNum1"
    ui.insts.propulsion = "ctrl.valNum2"
end

function M.new(...)
    return M(...);
end;

function M.ctor(self)
    InitInsts(self)
    M.super.ctor(self, ClientOHOH:GetPath_Loop("ReplicatedStorage.Resource.UI.PlayerInfoGui"));
end;

--------------外部调用接口--------
function M.UpdateHp(self,hp,maxHp)
    
    self.insts.hpText.Text = BigNumberHelper:ToString(hp).."/".. BigNumberHelper:ToString(maxHp)
    -- local hpRatio = math.clamp(hp/maxHp,0,1)
    -- print("update HP",hpRatio)
    -- self.insts.hpClipping.Size = UDim2.new(hpRatio,0,1,0)
    local TweenService = game:GetService("TweenService")

     
        local newHpRatio = math.clamp(hp / maxHp, 0, 1)
    
        -- 动态更新文本（仅对 hp 插值）
    
        -- 动态更新条形大小
        local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
        local tween = TweenService:Create(self.insts.hpClipping, tweenInfo, { Size = UDim2.new(newHpRatio, 0, 1, 0) })
        tween:Play()
end

function M.UpdateAttack(self,attack)
    self.insts.attack.Text =  BigNumberHelper:ToString(attack)
end


function M.UpdatePropulsion(self,propulsion)
    self.insts.propulsion.Text = BigNumberHelper:ToString(propulsion)
end

function M.Update(self,maxHp,hp,attack,propulsion)
    self:UpdateHp(maxHp,hp)
    self:UpdateAttack(attack)
    self:UpdatePropulsion(propulsion)
end


function M.dtor(self)
    M.super.dtor(self);
end;



return M